package com.bdsy.business.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bdsy.business.dao.OrderMapper;
import com.bdsy.business.model.Order;
import com.bdsy.business.service.OrderService;
import com.bdsy.common.utils.DateRandomUtil;
import com.bdsy.common.utils.DateUtil;

@Service("orderService")
public class OrderServiceImpl implements OrderService {

	@Autowired
	OrderMapper orderMapper;

	@Override
	public boolean add(Order order) {
		order.setOrderTime(DateUtil.getCurrentDate());
		//订单状态(0 1 )
		if(order.getOrderStatus() == null){
			order.setOrderStatus(0);
		}
		int result = orderMapper.insert(order);
		return result>0?true:false;
	}

	@Override
	public List<Map> selectOrderById(String userId) {
		List<Map> orderList = orderMapper.selectOrderById(userId);
		return orderList;
	}

	@Override
	public List<Map> orderListById(String userId,int orderStatus,int status) {
		List<Map> orderList = orderMapper.orderListById(userId,orderStatus,status);
		return orderList;
	}

	@Override
	public boolean updateOrderStatus(Order order, int status) {
		if(status == 1){
			order.setOrderStatus(1);//已付款代发货
		}
		int result = orderMapper.updateOrderStatus(order);
		return result>0?true:false;
	}

	@Override
	public List<Map> selectOrderByIdStatus(String userId,int status) {
		@SuppressWarnings("rawtypes")
		List<Map> orderList = orderMapper.selectOrderByIdStatus(userId, status);
		return orderList;
	}

	@Override
	public List<String> selectOrderId(String userId,int status) {
	List<String> orderIdList = orderMapper.selectOrderId(userId,status);
		return orderIdList;
	}

	@Override
	public List<Map> selectOrderByOrderId(String orderId,int status) {
		List<Map> orderList = orderMapper.selectOrderByOrderId(orderId,status);
		return orderList;
	}

	@Override
	public boolean deleteOrderById(List<String> pIds) {
		int result = orderMapper.deleteOrderById(pIds);
		return result>0?true:false;
	}

	@Override
	public List<Map> orderListByIdStatus(String userId, int status) {
		List<Map> orderList = orderMapper.orderListByIdStatus(userId, status);
		return orderList;
	}

	@Override
	public int acount(String userId) {
		int count = orderMapper.acount(userId);
		return count;
	}

	@Override
	public int ncount(String userId) {
		int ncount = orderMapper.ncount(userId);
		return ncount;
	}

	@Override
	public List<Map> selectNOrderById(String userId) {
		List<Map> nOrderList = orderMapper.selectNOrderById(userId);
		return nOrderList;
	}

	@Override
	public List<Map> saleStatis(String userId) {
		List<Map> saleStatis = orderMapper.saleStatis(userId);
		return saleStatis;
	}

	@Override
	public List<Map> areadyOrderList(String userId, int shopTypeId,int lx,int qx) {
		List<Map> areadyOrderList = orderMapper.areadyOrderList(userId, shopTypeId,lx,qx);
		return areadyOrderList;
	}

	@Override
	public List<Map> nareadyOrderList(String userId, int shopTypeId,int orderStatus,int status, int qx) {
		List<Map> nareadyOrderList = orderMapper.nareadyOrderList(userId, shopTypeId,orderStatus,status, qx);
		return nareadyOrderList;
	}

	@Override
	public List<Map> orderListByUserIdStatus(String userId, int shopTypeId, int orderStatus, int status) {
		List<Map> orderList = orderMapper.orderListByUserIdStatus(userId, shopTypeId, orderStatus, status);
		return orderList;
	}

}
